import operator

base_operator = {"+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv}


def calculate():
    first_num = get_num()
    op = get_operator()
    second_num = get_num('second')
    try:
        result = op(first_num, second_num)
    except ZeroDivisionError as error:
        print('error: {}, try again'.format(error))
        calculate()
    else:
        print("result is {}".format(result))


def get_num(index='first'):
    try:
        input_num = int(input('input {} num:'.format(index)))
    except ValueError:
        print('must input a number')
        get_num(index)
    else:
        return input_num


def get_operator():
    key = input('input the operator: ')

    try:
        op = base_operator[key]
    except KeyError:
        print("operator error, input again")
        get_operator()
    else:
        return op


calculate()
